<?php

namespace app\home\controller;


use think\facade\App;
use think\facade\Request;

class UrlGroupRelation extends Base {
    
    protected function initialize()
    {
        parent::initialize();
        $this->checkLogin();
    }
    
    /**
     * @desc 我的链接
     */
    public function index() {
        $params['id']   = input('id', 0);
        $params['urlId'] = input('urlId', 0);

        $data = model('UrlGroupRelation', 'logic')->index($params, $this->userId);

        $this->assign($data);
        return view();
    }
    
    /**
     * @desc 添加分组
     */
    public function add() {
        $params = [
            'urlId'   => input('urlId/a'),
            'groupId' => input('groupId')
        ];

        $logic = model('UrlGroupRelation', 'logic');
        $data = [];
        try {
            $data = $logic->add($params, $this->userId);
        } catch (\Exception $e) {
            $logic->errorCode = EC_FAILURE;
            $logic->message = $e->getMessage();
        }
        return send_response($data, $logic->errorCode, $logic->message);
    }
    
    /**
     * @desc 创建链接
     */
    public function del() {
        $id = input('id', 0);

        $logic = model('UrlGroupRelation', 'logic');
        $data = [];
        try {
            $data = $logic->del($id, $this->userId);
        } catch (\Exception $e) {
            $logic->errorCode = EC_FAILURE;
            $logic->message = $e->getMessage();
        }
        return send_response($data, $logic->errorCode, $logic->message);
    }
}
